﻿using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Text;

namespace OpenCvSharpExtension
{
    public class CameraHelper
    {
        /// <summary>
        /// 获取可用的摄像头数量
        /// </summary>
        /// <returns></returns>
        public static int GetMaxCameraCount()
        {
            int count = 0;
            for (int i = 0; i < 20; i++)
            {
                var cap = VideoCapture.FromCamera( i, VideoCaptureAPIs.ANY);
                if (cap.IsOpened())
                {
                    count++;
                    cap.Dispose();
                    continue;
                }
                else
                {
                    return count;
                }

            }
            return count;
        }
    }
}
